/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package daw.bean;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Christian
 */
@Entity
@Table(name = "delito")
@NamedQueries({@NamedQuery(name = "Delito.findAll", query = "SELECT d FROM Delito d"),
@NamedQuery(name = "Delito.findByIdDelito", query = "SELECT d FROM Delito d WHERE d.idDelito = :idDelito"),
@NamedQuery(name = "Delito.findByNombre", query = "SELECT d FROM Delito d WHERE d.nombre = :nombre")})
public class Delito implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idDelito")
    private Integer idDelito;
    @Basic(optional = false)
    @Column(name = "nombre")
    private String nombre;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "delito")
    private List<DelitoSubdelito> delitoSubdelitoCollection;

    public Delito() {
    }

    public Delito(Integer idDelito) {
        this.idDelito = idDelito;
    }

    public Delito(Integer idDelito, String nombre) {
        this.idDelito = idDelito;
        this.nombre = nombre;
    }

    public Integer getIdDelito() {
        return idDelito;
    }

    public void setIdDelito(Integer idDelito) {
        this.idDelito = idDelito;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public List<DelitoSubdelito> getDelitoSubdelitoCollection() {
        return delitoSubdelitoCollection;
    }

    public void setDelitoSubdelitoCollection(List<DelitoSubdelito> delitoSubdelitoCollection) {
        this.delitoSubdelitoCollection = delitoSubdelitoCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idDelito != null ? idDelito.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Delito)) {
            return false;
        }
        Delito other = (Delito) object;
        if ((this.idDelito == null && other.idDelito != null) || (this.idDelito != null && !this.idDelito.equals(other.idDelito))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "daw.bean.Delito[idDelito=" + idDelito + "]";
    }

    public String toXML(){
        String xml = "<delito>";
        xml+="<iddelito>"+getIdDelito()+"</iddelito>";
        xml+="<nombre>"+getNombre()+"</nombre>";
		xml+="</delito>";
        return xml;
    }

    public static String DelitoCollectionToXML(List<Delito> delitos){
        String xml="<delitos>";
        Iterator i = delitos.iterator();
        while(i.hasNext()){
            Delito c = (Delito)i.next();
            xml+=c.toXML();
        }
        xml+="</delitos>";
        return xml;
    }
}
